class ApplicationController < ActionController::Base
  session :session_key => '_mytodo_session_id'

  private
  def authorize
		
    if (cookies[:user_id] || '0').to_i > 0 
      session[:user_id] = cookies[:user_id].to_i
    end
		
    unless User.find_by_id(session[:user_id])
      redirect_to(:controller => "login", :action => "login")
    end
  end
  
  def authorize_admin
    unless User.role?(session[:user_id], 'admin')
      redirect_to(:controller => "login", :action => "need_admin")    			
    end
  end
  
  def authorize_manager
    unless User.role?(session[:user_id], 'manager')
      redirect_to(:controller => "login", :action => "need_manager")
    end
  end
end